<template>
  <div>
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '80px' } }">
        <a-form-item name="pyjm" label="" class="w-80">
          <a-input v-model:value="formState.pyjm" placeholder="医生姓名/助记码" />
        </a-form-item>
        <a-form-item name="dateRange" label="报告日期">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="mb-3">
        <BaseExport
          type="检验"
          name="医生工作量统计"
          code="000187"
          :search-params="{
            stdate: formState.dateRange?.[0],
            eddate: formState.dateRange?.[1],
            pyjm: formState?.pyjm
          }"
          >导出</BaseExport
        >
      </div>
      <BaseTable :loading="loading" column-code="000187" fill :data-source="tableData" bordered :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="onClickDetail(record)">明细</a-button>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <Edit v-model:open="openEdit" :row-data="rowData" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
// import { useRouter } from 'vue-router'
import dayjs from 'dayjs'
import SearchContainer from '@/components/SearchContainer'
import Edit from './components/Edit.vue'

// const router = useRouter()

const formRef = ref(null)
const openEdit = ref(false)
const rowData = ref({})
const formState = ref({
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})
const { loading, pagination, getData, tableData } = useTable({
  url: '/lis/LisRecord/getStatisticsDoctors',
  immediate: true,
  formatParams: () => {
    return {
      stdate: formState.value.dateRange?.[0],
      eddate: formState.value.dateRange?.[1],
      pyjm: formState.value?.pyjm
    }
  }
})

const onClickDetail = (row) => {
  rowData.value = { ...row }
  openEdit.value = true
  // router.push({
  //   path: '/workstation-inspect/query-detail',
  //   query: {
  //     empId: row.testEmpId,
  //     bgzs: row.bgzs,
  //     stdate: formState.value.dateRange?.[0],
  //     eddate: formState.value.dateRange?.[1]
  //   }
  // })
}
</script>
